package cn.copera.dyy.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.copera.dyy.common.service.BaseService;
import cn.copera.dyy.dao.ShopImageDao;
import cn.copera.dyy.entity.ShopImage;

/**
 * 店铺图片Service
 * 
 */
@Service
@Transactional(readOnly = true)
public class ShopImageService extends BaseService {

	@Autowired
	private ShopImageDao shopImageDao;
	

	@Transactional(readOnly = false)
	public void save(ShopImage shopImage) {
		shopImageDao.clear();
		shopImageDao.save(shopImage);
	}
	public List<ShopImage> loadImage(String shopId){
		return shopImageDao.findEntityList(new ShopImage(),"type asc", "shop.id='"+shopId+"' and flag = 'set'");
	}
	public ShopImage getShopImage(String id){
		return shopImageDao.get(id);
	}
	@Transactional(readOnly = false)
	public void delImage(String name,String shopId){
		ShopImage si = shopImageDao.findExistEntity(new ShopImage(), "name='"+name+"' and shop.id='"+shopId+"'");
		 shopImageDao.deleteRealById(si.getId());
	}
	
	public ShopImage findImage(String name,String shopId){
		return  shopImageDao.findExistEntity(new ShopImage(), "name='"+name+"' and shop.id='"+shopId+"'");
		 
	}
	@Transactional(readOnly = false)
	public void deleteImage(String shopId){
		ShopImage si = shopImageDao.findExistEntity(new ShopImage(), "shop.id = '"+shopId+"' and flag ='shop_img'");
		if (si != null) {
			shopImageDao.deleteRealById(si.getId());
		}
	}
	@Transactional(readOnly = false)
	public void removeImage(String imageId){
		shopImageDao.deleteRealById(imageId);
	}
	
	@Transactional(readOnly = false)
	public void update(ShopImage shopImage) {
		shopImageDao.clear();
		shopImageDao.saveEntity(shopImage);;
	}
}
